@extends("layouts.common")
@section("content")
    <script src="/js/datepicker/js/bootstrap-datetimepicker.min.js"></script>
    <link rel="stylesheet" href="/js/datepicker/css/bootstrap-datetimepicker.min.css" />
    <style>
        .panel .panel-heading .panel-actions {
            float: right;
            margin-right: -15px;
            height: 40px;
            font-size: 0;
            width: 30%;
            text-align: right;
        }
    </style>
    <div class="row">
        <div class="col-lg-12">
            @if (isset($errors) && count($errors) > 0)
                <div class="alert alert-danger alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-ban"></i> 错误</h4>
                    <ul>
                        @foreach ($errors->all() as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
            @if (Session::has('messages'))
                <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa fa-check"></i> 成功!</h4>
                    <ul>
                        @foreach (Session::get('messages') as $error)
                            <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                </div>
            @endif
        </div>
    </div>

    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header"><i class="fa fa-table"></i>收支明细</h3>
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a href="/welcome">Home</a></li>
                <li><i class="fa fa-table"></i>收支列表</li>
            </ol>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>搜索</strong></h2>
                </div>
                <form action="" method="get" class="form-inline">
                <div class="panel-body">

                        <div class="form-group">
                            <input type="text"  id="datetimepicker" name="year" class="form-control" placeholder="选择年份">
                        </div>
                        <div class="form-group">
                            <input type="text" id="datetimepicker1" name="month" class="form-control" placeholder="选择月份">
                        </div>

                </div>
                <div class="panel-footer">
                    <button type="submit" class="btn btn-sm btn-success"><i class="fa fa-dot-circle-o"></i> 搜索</button>
                    <button type="reset" class="btn btn-sm btn-danger"><i class="fa fa-ban"></i> 重置</button>
                </div>
                </form>
            </div>

        </div>
    </div>

    <div class="row">

        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-table red"></i><span class="break"></span><strong>结算列表</strong></h2>

                    {{--<div class="panel-actions">--}}
                        {{--<a href="/agent/add" style=""><i class="fa  fa-table"></i>交易记录&nbsp;&nbsp;</a>--}}
                        {{--<a href="/agent/add"><i class="fa  fa-plus"></i>添加代理&nbsp;&nbsp;</a>--}}
                    {{--</div>--}}
                </div>
                <div class="panel-body">
                    <table class="table table-condensed">
                        <thead>
                        <tr>
                            <th>年</th>
                            <th>月</th>
                            <th>收入</th>
                            <th>支出</th>
                            <th>留存</th>
                            <th>添加时间</th>
                            {{--<th>上级</th>--}}
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($data as $val)
                        <tr>
                            <td>{{$val->year}}</td>
                            <td>{{$val->month}}</td>
                            <td>{{$val->profit}}</td>
                            <td>{{$val->pay}}</td>
                            <td>{{$val->profit - $val->pay}}</td>
                            <td>{{$val->created_at}}</td>
                        </tr>
                         @endforeach

                        </tbody>
                    </table>
                    @include("layouts.page",['paginator'=>$data])
                </div>
            </div>
        </div><!--/col-->
    </div>
    <style>
        td,th{
            text-align: center;
        }
    </style>
    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要禁用么？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-danger active btn-sm model_delete" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要开启么？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-info active btn-sm model_delete" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="upgrade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">警告</h4>
                </div>
                <div class="modal-body">
                    你确定要升级代理吗？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                    <a  class="btn btn-info active btn-sm model_delete" data-val="" role="button">确定</a>
                </div>
            </div>
        </div>
    </div>
    <script>
        $(function () {
            $('#datetimepicker').datetimepicker({
                format: 'yyyy',
                weekStart: 1,
                autoclose: true,
                startView: 4,
                minView: 4,
                forceParse: false,
                language: 'zh-CN'
            });
            $('#datetimepicker1').datetimepicker({
                format: "mm",
                weekStart: 1,
                autoclose: true,
                startView: 3,
                minView: 3,
                forceParse: false,
                language: 'zh-CN'
            });
            $(".btn-delete").click(function(){
                $("#myModal").find('.modal-footer .btn-danger').attr('href', "/agent/close/" + $(this).attr("data-val"));
            });
            $(".btn-delete1").click(function(){
                $("#myModal1").find('.modal-footer .btn-info').attr('href', "/agent/open/" + $(this).attr("data-val1"));
            });
            $(".upgrade").click(function(){
                $("#upgrade").find('.modal-footer .btn-info').attr('href', "/agent/upgrade/" + $(this).attr("data-val"));
            });

            var search = location.search.substring(1);
            if (search) {
                try {
                    var query = JSON.parse('{"' + decodeURIComponent(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g, '":"') + '"}');

                    $.each(query, function(k, v) {
                        $('[name=' + k + ']').val(v);
                    });
                } catch (e) {
                    console.log(e);
                }

            }
        });
    </script>
@endsection